using UnityEngine;
using System.Collections;

public class TaskInfo : MonoBehaviour {
	
	public UISprite taskStatusSprite;
	public string targetWindowName;
	
	//TODO
	public GameObject NPCTarget;
	
	
	int taskStatus;
	GuideLogic guideLogic;
	
	void Awake(){
		//ModelLocator.getInstance().addEventListener(ClientToClientFlag.CLIENT_TASK_ONE_STATUS,GetListenner);
	}
	
	private void GetListenner(object o,DispatchEventArgs e)
	{
		taskStatus = (int)e.data[0];
		switch(taskStatus)
		{
		case GameDefine.NPCStatus_CanSubmit:
			taskStatusSprite.enabled = true;
			taskStatusSprite.spriteName = GameDefine.TASKSTATUS_COMPLETE;
			break;
		case GameDefine.NPCStatus_TaskAccept:
			taskStatusSprite.enabled = true;
			taskStatusSprite.spriteName = GameDefine.TASKSTATUS_CANACCESS;
			break;
		case GameDefine.NPCStatus_UnComplete:
			taskStatusSprite.enabled = true;
			taskStatusSprite.spriteName = GameDefine.TASKSTATUS_UNCOMPLETE;
			break;
		default:
			taskStatusSprite.enabled = false;
			break;
		}
		
		taskStatusSprite.MakePixelPerfect();
	}
	
	void Start(){
		guideLogic = Camera.main.GetComponent<GuideLogic>();
		
		guideLogic.setGuidePos(gameObject,3,new Vector3(155,0,0));
	}
	
	//
	void Update(){
		taskStatus = TaskStatus.Instance().taskStatus;
		
		switch(taskStatus)
		{
		case GameDefine.NPCStatus_CanSubmit:
			taskStatusSprite.enabled = true;
			taskStatusSprite.spriteName = GameDefine.TASKSTATUS_COMPLETE;
			break;
		case GameDefine.NPCStatus_TaskAccept:
			taskStatusSprite.enabled = true;
			taskStatusSprite.spriteName = GameDefine.TASKSTATUS_CANACCESS;
			break;
		case GameDefine.NPCStatus_UnComplete:
			taskStatusSprite.enabled = true;
			taskStatusSprite.spriteName = GameDefine.TASKSTATUS_UNCOMPLETE;
			
			NPCTarget = GameObject.Find("Door");
			
			break;
		default:
			taskStatusSprite.enabled = false;
			break;
		}
		
		taskStatusSprite.MakePixelPerfect();
	}
	
	void OnClick(){
		//ModelLocator.getInstance().dispacthEvent(ClientToClientFlag.CLIENT_CLICK_SCENE_OBJ,new object[]{NPCTarget});
		SceneClickLogic.getInstance().dispatchSceneObjClick(NPCTarget);
		
		UIManagement.Instance().shallOpenWindowName = targetWindowName;
		//
		GameDefine.Click_Task_One = true;
	}
	
	/*
	void OnDestroy(){
		ModelLocator.getInstance().removeEventListener(ClientToClientFlag.CLIENT_CLICK_NPC);
	}
	*/
}
